home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
DEMOS
/
3D_DEMO_3
/
!Demo3
/
c
/
demo3
next >
Wrap
Text File
|
1992-02-04
|
6KB
|
285 lines
/******************************************************************************
* *
* grp.c *
* *
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <swis.h>
#include <os.h>
#include <bbc.h>
#include "GrpLib.h"
void SetTxtCurPos(int x, int y)
{
os_error *err;
err=bbc_tab(x,y);
}
int GetClock(void)
{
os_regset regs;
char blk[16];
int i=0;
int t=0;
regs.r[0]=0x01; /* read system clock */
regs.r[1]=(int)blk;
os_swi(OS_Word,®s);
t+=(int)(blk[i++])<<0;
t+=(int)(blk[i++])<<8;
t+=(int)(blk[i++])<<16;
t+=(int)(blk[i++])<<24;
return(t);
}
void SetMouseArea(int left, int bottom, int right, int top)
{
os_regset regs;
char blk[16];
int i=0;
blk[i++]=(char) 1; /* define mouse co-ordinate bounding box */
blk[i++]=(char) (left & 0xFF); blk[i++]=(char) ((left >>8) & 0xFF);
blk[i++]=(char) (bottom & 0xFF); blk[i++]=(char) ((bottom>>8) & 0xFF);
blk[i++]=(char) (right & 0xFF); blk[i++]=(char) ((right >>8) & 0xFF);
blk[i++]=(char) (top & 0xFF); blk[i++]=(char) ((top >>8) & 0xFF);
regs.r[0]=0x15; /* define pointer and mouse parameters */
regs.r[1]=(int)blk;
os_swi(OS_Word,®s);
}
void SetMousePos(int x, int y)
{
os_regset regs;
char blk[16];
int i=0;
blk[i++]=(char) 3; /* set mouse position */
blk[i++]=(char) (x & 0xFF); blk[i++]=(char) ((x>>8) & 0xFF);
blk[i++]=(char) (y & 0xFF); blk[i++]=(char) ((y>>8) & 0xFF);
regs.r[0]=0x15; /* define pointer and mouse parameters */
regs.r[1]=(int)blk;
os_swi(OS_Word,®s);
}
void ReadMouse(int *x, int *y, int *b)
{
os_regset regs;
os_swi(OS_Mouse,®s);
*x=regs.r[0];
*y=regs.r[1];
*b=regs.r[2];
}
int Inkey()
{
os_regset regs;
regs.r[0] = 129; /* kb read */
regs.r[1] = 0; /* wait time low byte */
regs.r[2] = 0; /* wait time high byte */
os_swi(OS_Byte,®s);
return( (regs.r[2]==0) ? regs.r[1] : 0);
}
int main()
{
int i;
int time=0;
int msx,msy,msbut,msorgx,msorgy;
int kbbut;
int stp=10;
int ra,rs,rt,x,y,z,v;
char *spr1,*spr2,*spr3;
Object *cvx1,*cvx2,*cvx3;
Object *sch1,*sch2,*sch3;
Object *ObjTab[4];
int vtpos[4][6];
Object *obs;
int curobj;
Envi *envi;
InitGrp();
Change2DParm(0,0,319,255);
Change3DParm(80,64,320);
obs = MakeObj("", NULL,0);
cvx1 = MakeObj("<GrpObj$Dir>.crayon1", CVX ,1);
cvx2 = MakeObj("<GrpObj$Dir>.crayon2", CVX ,0);
sch1 = MakeObj("<GrpObj$Dir>.plane1", SCH ,0);
sch2 = MakeObj("<GrpObj$Dir>.plane2", SCH ,1);
sch3 = MakeObj("<GrpObj$Dir>.sub8", SCH ,2);
ObjTab[0]=cvx1;
ObjTab[1]=sch1;
ObjTab[2]=sch2;
ObjTab[3]=sch3;
PlaceObj(obs,0,0,0,0,0,-2000);
envi = MakeEnvi(1, 0, 0x50);
MkVec4(envi->DirecSrc[0], 128, 128, 128, 0);
MkVec4(envi->PonctSrc[0], 0, 200, 0, 100000);
SetMouseArea(0,0,1279,1023);
SetMousePos(640,512);
ReadMouse(&msorgx,&msorgy,&msbut);
v=0;
curobj=0;
for(i=0;i<4;i++) {
vtpos[i][0]=0;
vtpos[i][1]=0;
vtpos[i][2]=0;
vtpos[i][3]=0;
vtpos[i][4]=0;
vtpos[i][5]=0;
PlaceObj(ObjTab[i], 0,0,0, 0,0,0);
}
while (1==1) {
SetTxtCurPos(0,0); printf("%d",GetClock()-time);
time=GetClock();
x=y=z=ra=rs=rt=0;
for(i=0;i<4;i++) {
switch(i) {
case 0: Change2DParm( 0, 0,159,127); break;
case 1: Change2DParm(160, 0,159,127); break;
case 2: Change2DParm( 0,128,159,127); break;
case 3: Change2DParm(160,128,159,127); break;
}
PlotObj(envi,obs,ObjTab[i]);
ReadObjCoord(ObjTab[i], &ra,&rs,&rt, &x,&y,&z);
ra+=vtpos[i][0];
rs+=vtpos[i][1];
rt+=vtpos[i][2];
x+=vtpos[i][3]; vtpos[i][3]=0;
y+=vtpos[i][4]; vtpos[i][4]=0;
z+=vtpos[i][5]; vtpos[i][5]=0;
PlaceObj(ObjTab[i], ra,rs,rt, x,y,z);
}
x=y=z=ra=rs=rt=0;
ReadMouse(&msx,&msy,&msbut);
msx-=msorgx;
msy-=msorgy;
SetMousePos(640,512);
kbbut = Inkey();
rt += (msx*stp);
rs += (msy*stp);
if (msbut==0x01<<2) ra+=stp;
if (msbut==0x01<<0) ra-=stp;
switch (kbbut) {
case '+' : z=+15; break;
case '-' : z=-15; break;
case 'S' :v=0;ra=0;rs=0;rt=0;
for(i=0;i<4;i++) {
vtpos[i][0]=0;
vtpos[i][1]=0;
vtpos[i][2]=0;
vtpos[i][3]=0;
vtpos[i][4]=0;
vtpos[i][5]=0;
PlaceObj(ObjTab[i], 0,0,0, 0,0,0);
}
break;
}
vtpos[curobj][0]+=ra;
vtpos[curobj][1]+=rs/128;
vtpos[curobj][2]+=rt/64;
vtpos[curobj][3]=x;
vtpos[curobj][4]=y;
vtpos[curobj][5]=z;
switch (kbbut) {
case '1': curobj=0; break;
case '2': curobj=1; break;
case '3': curobj=2; break;
case '4': curobj=3; break;
case ' ': return(0);
}
Change2DParm(0,0,319,255);
GrpReg[0]=0;
GrpReg[1]=0;
GrpReg[2]=319;
GrpReg[3]=0;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
GrpReg[0]=0;
GrpReg[1]=128;
GrpReg[2]=319;
GrpReg[3]=128;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
GrpReg[0]=0;
GrpReg[1]=255;
GrpReg[2]=319;
GrpReg[3]=255;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
GrpReg[0]=0;
GrpReg[1]=0;
GrpReg[2]=0;
GrpReg[3]=255;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
GrpReg[0]=160;
GrpReg[1]=0;
GrpReg[2]=160;
GrpReg[3]=255;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
GrpReg[0]=319;
GrpReg[1]=0;
GrpReg[2]=319;
GrpReg[3]=255;
GrpReg[8]=0xFF;
CallGrp(GrpReg,GrpStack,Uni2DPoly2);
SwapView(0x00000000);
}
}